package com.cjzuji.rental.util;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateUtil {
    public static final String DATETIME_FORMAT_1 = "yyyy-MM-dd HH:mm:ss";
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern(DATETIME_FORMAT_1);
    public static String longtoStr(Long date) {
        // 创建SimpleDateFormat对象并设置格式
        SimpleDateFormat sdf = new SimpleDateFormat(DATETIME_FORMAT_1);

        // 将时间戳转换为Date对象，然后格式化为字符串
        String dateString = sdf.format(new Date(date));
        return dateString;
    }

    //当天开始时间
    public static String getTodayStart() {
        return LocalDate.now().atStartOfDay().format(FORMATTER);
    }
    //当天结束时间
    public static String getTodayEnd() {
        return LocalDate.now().atTime(LocalTime.MAX).format(FORMATTER);
    }
    public static void main(String[] args) {
        System.out.println(getTodayStart());
        System.out.println(getTodayEnd());
    }
    /**
     * 获取系统当前时间 yyyy-MM-dd HH:mm:ss
     *
     * @return String
     */
    public static String getStandardNowTime() {
        SimpleDateFormat sdf = getDateFormat(DATETIME_FORMAT_1);
        return sdf.format(new Date());
    }
    /**
     * 根据传入format格式化日期
     *
     * @param format format
     * @return SimpleDateFormat
     */
    public static SimpleDateFormat getDateFormat(String format) {
        return new SimpleDateFormat(format);
    }
}
